//ajax包装刷新方法
function ajaxDefrence(){
    $.ajax({
        url: 'student/list.php',
        type: "POST",
        data: {
            size:size,
            page:page,
            name:name,
            count:maxCount,
            list:[
                {
                    id:"id",
                    name:"name",
                    sex:"sex",
                    age:"age",
                    city:"city",
                    edu:"edu",
                    no:"no"
                }
            ]
        },
        dataType: 'json',
        async: true,
        success: function (data) {
            query(data);
        },
    });
}
ajaxDefrence();
//添加方法
$(function () {
    $("#stuAdd").click(function () {
        let stuName=$("#register .name").val();
        let stuAge=$("#register .age").val();
        let stuCity=$("#register .city").val();
        let stuSex=$("#register .sex").val();

        $.ajax({
            url: 'student/add.php',
            type:"POST",
            data: {
                "name":stuName,
                "age":stuAge,
                "city":stuCity,
                "sex":stuSex,
                "edu": "xxx",
                "no":"123"
            },
            dataType: 'json',
            async: true,
            success:function (data) {
                if(data.code==="200"){
                    $("#register").fadeOut(300);
                    ajaxDefrence();
                }else {
                    alert(data.msg);
                }
            },
        });
    });
    //修改方法
    $("#stuChange").click(function () {
        let stuName=$("#changeCover .name").val();
        let stuAge=$("#changeCover .age").val();
        let stuCity=$("#changeCover .city").val();
        let stuSex=$("#changeCover .sex").val();
        let stuId=$("#changeCover #id").val();
        $.ajax({
            url: 'student/update.php',
            type:"POST",
            data: {
                "id":stuId,
                "name":stuName,
                "age":stuAge,
                "city":stuCity,
                "sex":stuSex
            },
            dataType: 'json',
            async: true,
            success:function (data) {
                if(data.code==="200"){
                    ajaxDefrence();
                    $("#changeCover").fadeOut(300);
                }else {
                    alert(data.msg);
                }
            },
        });
    });
});